package org.abc.fund.controller.user.response;

import lombok.Builder;
import lombok.Data;
import org.abc.fund.entity.user.Role;
import org.abc.fund.entity.user.User;

import java.time.LocalDateTime;
import java.util.Set;

@Data
@Builder
public class UserResponse {

  private Long id;
  private String username;
  private String email;
  private String realName;
  private Set<Role> roles;

  private User.Gender gender;
  private int age;

  private LocalDateTime createdAt;
  private LocalDateTime updatedAt;

  /**
   * 从User实体转换为UserResponse DTO的静态工厂方法
   *
   * @param user 用户实体
   * @return 转换后的DTO
   */
  public static UserResponse fromEntity(User user) {
    return UserResponse.builder()
        .id(user.getId())
        .username(user.getUsername())
        .email(user.getEmail())
        .realName(user.getRealName())
        .roles(user.getRoles())
        .age(user.getAge())
        .gender(user.getGender())
        .createdAt(user.getCreatedAt())
        .updatedAt(user.getUpdatedAt())
        .build();
  }
}
